﻿using System;
using System.Web.UI.WebControls;
using Bingosoft.Modules.DataDictionary;
using Bingosoft.Web.Utils;

namespace Bingosoft.WebApp.Modules.DeliveredManager
{
    public partial class DeliveredSelect : System.Web.UI.ListPage
    {
        private DeliveredService storageService = new DeliveredService();
        protected string titleStr
        {
            get;
            set;
        }

        protected string Type
        {
            get;
            set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //if(!IsPostBack)
            {
                if (Request["Type"] != null)
                {
                    Type = Request["Type"].ToString();
                    ((TextBox)ControlHelper.FindControl(GridSearch, "txtOrgId")).Text = Bingosoft.Security.SecurityContext.User.Properties["OrgId"] + "";
                    //this.GridSearch.FindControl<TextBox>("txtType").Text = Type;
                    switch (Type)
                    { 
                        case"1":
                            this.titleStr = "新购配件或材料出库选择页面";
                            this.SmartDataSource1.SelectCommand = "Storage.select.list1";
                            this.SmartDataSource1.SelectCountCommand = "Storage.select.list1.count";
                            this.SmartDataSource1.DataBind();
                            break;
                        case "2":
                            this.titleStr = "维修良好的配件或材料出库选择页面";
                            this.SmartDataSource1.SelectCommand = "Storage.select.list2";
                            this.SmartDataSource1.SelectCountCommand = "Storage.select.list2.count";
                            this.SmartDataSource1.DataBind();
                            break;
                        case "3":
                            this.titleStr = "委外修配件出库选择页面";
                            this.SmartDataSource1.SelectCommand = "Storage.select.list3";
                            this.SmartDataSource1.SelectCountCommand = "Storage.select.list3.count";
                            this.SmartDataSource1.DataBind();
                            break;
                        case "4":
                            this.titleStr = "下车配件或材料出库选择页面";
                            this.SmartDataSource1.SelectCommand = "Storage.select.list4";
                            this.SmartDataSource1.SelectCountCommand = "Storage.select.list4.count";
                            this.SmartDataSource1.DataBind();
                            break;
                        default:
                            break;
                    }
                }
            }
        }

        protected void SearchGrid(object sender, EventArgs e)
        {
            this.GridSearch.Search();
        }

        protected void RefreshGrid(object sender, EventArgs e)
        {
            this.GridSearch.Refresh();
        }

        protected void DeleteDictionaryItem(object sender, EventArgs e)
        {
            var _sender = sender as ImageButton;
            String Id = _sender.Attributes["_KeyId"];

            this.storageService.DeleteDataItem(Id);

            RefreshGrid(sender, e);
        }

        protected void SmartGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //ImageButton enableImgBtn = e.Row.FindControl("EnableImageButton") as ImageButton;
                //ImageButton disableImgBtn = e.Row.FindControl("DisableImageButton") as ImageButton;
                //string status = enableImgBtn.Attributes["_STATUS"];
                //if ("enabled".Equals(status))
                //{
                //    enableImgBtn.Visible = false;
                //    disableImgBtn.Visible = true;
                //}
                //else
                //{
                //    enableImgBtn.Visible = true;
                //    disableImgBtn.Visible = false;
                //}
            }
        }

        protected void LinkButtonExport_Click(object sender, EventArgs e)
        {
            this.SmartGridView1.SaveAsXls(string.Format(titleStr + "{0:yyyyMM}.xls", DateTime.Now), true, this.SmartGridView1.Columns.Count - 1);
        }
    }
}